package net.oschina.app.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;

import net.oschina.app.R;
import net.oschina.app.base.BaseActivity;
import net.oschina.app.fragment.ExploreFriendsFragment;
import net.oschina.app.fragment.MeBlogFragment;
import net.oschina.app.fragment.MeFavoriteFragment;
import net.oschina.app.fragment.MeFollowFragment;
import net.oschina.app.fragment.MeMessageFragment;
import net.oschina.app.interf.FragmentType;

/**
 * Created by wei03 on 2017/1/17.
 */

public class RvFragmentActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);
        initActionBar();
    }

    private void initActionBar() {
        String displayType = getIntent().getStringExtra(FragmentType.FRAGMENT_TYPE);
        if (!TextUtils.isEmpty(displayType)) {
            int actionBarTitle = 0;
            Fragment fragment = null;
            switch (displayType) {
                case FragmentType.TYPE_ME_BLOG:    //博客
                    actionBarTitle = R.string.actionbar_title_user_blog;
                    fragment = new MeBlogFragment();
                    break;
                case FragmentType.TYPE_ME_FANS:  //粉丝,关注
                    actionBarTitle = R.string.team_issue_detail;
                    fragment = new MeFollowFragment();
                    break;
                case FragmentType.TYPE_ME_FAVORITE:  //收藏
                    actionBarTitle = R.string.actionbar_title_user_favorite;
                    fragment = new MeFavoriteFragment();
                    break;
                case FragmentType.TYPE_ME_MESSAGE:  //消息
                    actionBarTitle = R.string.actionbar_title_mes;
                    fragment = new MeMessageFragment();
                    break;
                case FragmentType.TYPE_EXPLORE_FRIENDS:  //消息
                    actionBarTitle = R.string.active;
                    fragment = new ExploreFriendsFragment();
                    break;
                case FragmentType.TYPE_EXPLORE_ACTIVITIES:  //消息
                    actionBarTitle = R.string.actionbar_title_active;
                    fragment = new ExploreFriendsFragment();
                    break;
                default:
                    finish();
                    break;
            }
            if (actionBarTitle != 0) {
                setActionBarTitle(actionBarTitle);
            }
            FragmentTransaction ft = getSupportFragmentManager()
                    .beginTransaction();
            ft.replace(R.id.container_open_soft, fragment).commit();
        }
    }
}
